package com.cqut.forum.unit;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

import com.cqut.forum.util.MyQuickSort;

public class test {
	public void test1 (){
		Class<test> clazz = test.class;
		System.out.println(clazz.getName());
	}
	public void test2(){
		long l = 2;
		int a = (int) l;
		System.out.println(a);
	}
	public void test3(){
		int[] t = new int[6];
		t[0] = 5;
		t[1] = 2;
		t[2] = 1;
		t[3] = 6;
		t[4] = 25;
		t[5] = 3;
		MyQuickSort.quickSort(t);
	}
	@Test
	public void test4(){
		Date d = new Date();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:MM:SS");
		System.out.println(format.format(d));
		Date tody = new Date();
		System.out.println(format.format(tody));
		//System.out.println(new Date("yyyy-MM-dd"));
		
		
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE,   -1);
		//cal.add(Calendar.HOUR, 0);
		//cal.add(Calendar.MINUTE, 0);
		//cal.add(Calendar.SECOND, 0);
		cal.clear(Calendar.HOUR_OF_DAY);
		cal.clear(Calendar.MINUTE);
		cal.clear(Calendar.SECOND);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.HOUR_OF_DAY, 0);
		//String yesterday = new SimpleDateFormat( "yyyy-MM-dd HH:MM:S").format(cal.getTime());
		System.out.println(format.format(cal.getTime().clone()));
	}
	public void test5(){
		//String url = "<p>adfasdf</p><img src='../../../../user/userArticle/xunxun/20130219/test.jpg'/>";
		String url1 = "adfasd";
		
		//url.replaceAll("src='../../../../", "src='../../../");
		url1.replaceAll("a", "s");
		System.out.println(url1);
	}
	
	public void test6(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("a_a", "yangxun1");
		map.put("b_b", "yangxun2");
		map.put("c_c", "yangxun3");
		map.put("d_d", "yangxun4");
		
		String[] keys = (String[]) map.keySet().toArray();
		
		
	}
	public void test7(){
		String t = "a_a";
		t = t.replace('_', ' ');
		System.out.println(t);
		Pattern pattern = Pattern.compile("_");
		Matcher matcher = pattern.matcher("a_a_a");
		//替换第一个符合正则的数据
		System.out.println(matcher.replaceAll(""));
		String newKey = "";
		String[] k = t.split("_");
		for(int i =0;i<k.length;i++){
			//newKey = newKey + Character.toUpperCase(k[i].charAt(0))+key.substring(1, key.length());
		}
	}
	
	@Test
	public void changeMapKey(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("user_id", "1");
		map.put("user_name", "xun");
		
		Map<String, Object> result = new HashMap<String, Object>();
		Object[] keys = map.keySet().toArray();
		for(Object kk:keys){
			String key = kk.toString();
			if(map.containsKey(key)){
				String[] k = key.split("_");
				int length = k.length;
				String newKey = length>0?k[0]:key;
				for(int i =1;i<length;i++){
					newKey = newKey + Character.toUpperCase(k[i].charAt(0))+k[i].substring(1, k[i].length());
				}
				result.put(newKey, map.get(key));
			}
		}
		System.out.println(result.size());
	}
}
